package debtbundler.presentation.basecomponents;

import java.util.HashSet;
import java.util.Set;


public abstract class SelectableDomainEditorImpl<T> extends SelectableComponent implements DomainEditorComponent<T> {

	private static final long serialVersionUID = 1L;
	protected Set<DomainEditorListener> listeners = new HashSet<DomainEditorListener>(); 

	@Override
	public boolean addDomainEditorListener(DomainEditorListener listener) {
		return listeners.add(listener);
	}

	/**
	 * Notifies the listeners of this domain editor that a value has 
	 * been modified in this editor.
	 */
	protected void fireDomainValueModified() {
		for (DomainEditorListener listener : listeners) {
			listener.handleValueEdited(this);
		}
	}
	
	/**
	 * Notifies the listeners of this domain editor that a value has 
	 * been modified in a given editor.
	 * 
	 * @param editor	the editor in which a domain value has been modified
	 */
	protected void fireDomainValueModified(DomainEditorComponent<?> editor) {
		for (DomainEditorListener listener : listeners) {
			listener.handleValueEdited(this);
		}
	}

	@Override
	public boolean removeDomainEditorListener(DomainEditorListener listener) {
		return listeners.remove(listener);
	}

}
